<?php 
$GLOBALS['Md'] = "TimeClock";
$GLOBALS['Pd'] = "R";
require_once($_SERVER['DOCUMENT_ROOT']."/defaultconf.mex");
print heade(); 
print body(); 
module($BSD['DB00']);
office_header($_SESSION[$SESSOF]);
include($GLOBALS['PAD']."Modules/Exchange/main.obj.php");
include($GLOBALS['PAD']."Modules/Exchange/Reports/views.inc.php");
?>
<table width="100%"  border="0" cellpadding="10">
<?php

$CSS['PrintClass'] = "All";
$CSS['lines'] = "";
 
if (isset($_POST['View'])) {
	$View = $_POST['View'];
	} elseif (isset($_GET['View'])) {
	$View = $_GET['View'];
	}
if(isset($View)) {
	if (!isset($time_ini)) {
		if(isset($_POST['time_ini'])) {
			$time_ini = $_POST['time_ini'];
			$time_end = $_POST['time_end'];
		} else {
			if (isset($_POST['mtime'])) {
			$time_ini = mktime(0,0,0,$_POST['mtime'],$_POST['dtime'],$_POST['ytime']);
			$time_end = mktime(24,60,60,$_POST['mtime'],$_POST['dtime'],$_POST['ytime']);
			} else { 
			$time_ini = mktime(0,0,0,$_POST['mtime_i'],$_POST['dtime_i'],$_POST['ytime_i']);
			$time_end = mktime(24,60,60,$_POST['mtime_e'],$_POST['dtime_e'],$_POST['ytime_e']);
			}
		}
	}
}

	$query_ini = '';
	 $query_end = '';
	 $query_office = '';
	 $query_type = '';
	 $query_in = '';
	 $query_out = '';
	 $query_rates = '';

		for ($S = 1; $S <= $_SESSION['modules_total']; $S++) {
		$M = "Module".$S;
		$P = "Perm".$S;
		if ($_SESSION[$M] == "12") {
		$p = $_SESSION[$P];
		} else {
		$p = 'Perm1';
		}
	}

if ($_SESSION[$p] == 'B') { ?>
  <tr>
    <td>
 <?php if (!isset($View)) { ?>
<form action="index.php?View=AllDetails" method="post">
	<p>Report Geral </p>
	<table width="100%"  border="0" cellpadding="10" cellspacing="1">
 <tr bgcolor="#009999">
   <td colspan="2">Escolha um periodo</td>
 </tr>
 <tr bgcolor="#F2F2F2"><td colspan="2"><p>OpÇ&otilde;es</p>
   <p> Periodo do RelatÓrio | Início: <?php echo form_input_date("time_i",$GLOBALS['T']);?>
       Fim: 
         <?php echo form_input_date("time_e",$GLOBALS['T']);?>
       | Mostrar totais por loja:
       <input name="View" type="checkbox" id="View" value="Days">
      </p>
   </td>
 </tr>
 <tr bgcolor="#F2F2F2">
   <td>&nbsp;</td>
   <td><input name="Refresh" type="submit" id="Refresh" value="Mostrar"></td>
 </tr>
    </table>
	 </form>
	 <?php 	} else { ?>
      <p><?php if (isset($View)) {
		if ($View == "Days") { 
		print "<a href=\"index.php\">Geral</a> > Dias";
		}
		if ($View == "Offices") { 
		print "<a href=\"index.php\">Geral</a> > <a href=\"index.php?View=Days\">Dias</a> > Lojas";
		}
		if ($View == "Details") { 
		print "<a href=\"index.php\">Geral</a> > <a href=\"index.php?View=Days\">Dias</a> > <a href=\"index.php?View=Offices\">Lojas</a> > Detalhes";
		}
		
	} ?></p>
      <table width="100%"  border="0" cellpadding="10" cellspacing="1">
        <?php 	

  if (isset($View) && $View == "Days") {   

  	if (isset($View) && $View == "All") {   
	 print main($time_ini,$time_end);
	
	}
	if (isset($View) && $View == "Days") {
	
	print days($time_ini,$time_end,$CSS);
       
	} 
	if (isset($View) && $View == "Offices") {
			
		print offices($time_ini,$time_end,"B",$_POST['office'],$CSS);
	}
	if (isset($View) && $View == "Details") {
 ?>			
    </table>
      <?php echo details($time_ini,$time_end,$_POST['office']);?>
    </td>
  </tr>
  <?php } 
  } else {	
  	if (isset($View) && $View == "AllDetails") {
 ?>			
    </table>
      <?php echo alldetails($time_ini,$time_end,$CSS);?>
    </td>
  </tr>
  <?php }
  } ?>
  <form action="print.php" target="_blank" method="post">
  <tr>
	<td>
	<input type="hidden" name="time_ini" value="<?php echo $time_ini;?>">
	<input type="hidden" name="time_end" value="<?php echo $time_end;?>">
	<input type="hidden" name="office" value="<?php echo $_POST['office'];?>">
	<input type="hidden" name="View" value="<?php echo $View;?>">
	<input type="submit" name="Print" value="Imprimir Relat�rio">
	</td>
  </tr>
	</form>
  <?php	} 

  } elseif($_SESSION[$p] == 'R' || $_SESSION[$p] == 'S') { ?>
  <tr>
  <td> 
  <?php if (!isset($View)) { ?>
  <form action="index.php?View=DailyReport" method="post" enctype="application/x-www-form-urlencoded">
	<p>Total de operaÇ&otilde;es do dia</p>
	<table width="100%"  border="0" cellpadding="10" cellspacing="1">
 <tr bgcolor="#009999">
   <td colspan="2">Escolha um dia</td>
 </tr>
 <tr bgcolor="#F2F2F2"><td colspan="2"><p>Dia:
		<?php echo form_input_date("time",$GLOBALS['T']);?>
        </p></td></tr>
 <tr bgcolor="#F2F2F2">
   <td>&nbsp;</td>
   <td><input name="Refresh" type="submit" id="Refresh" value="Mostrar"></td>
 </tr>
    </table>
	 </form>
	<?php } else { ?>
	</td>
  </tr>
  <tr>
    <td>
	<p>Total de operaÇ&otilde;es do dia</p>
	<?php
	print offices($time_ini,$time_end,"S",$_SESSION[$SESSOF],$CSS); ?>
	<p>Detalhe das opera��es do dia</p>
	<?php
	print details($time_ini,$time_end,$_SESSION[$SESSOF],$CSS);?>
	</td>
  </tr>
	<form action="print.php" target="_blank" method="post">
  <tr>
	<td>
	<input type="hidden" name="time_ini" value="<?php echo $time_ini;?>">
	<input type="hidden" name="time_end" value="<?php echo $time_end;?>">
	<input type="hidden" name="office" value="<?php echo $_SESSION[$SESSOF];?>">
	<input type="hidden" name="View" value="<?php echo $View;?>">
	<input type="submit" name="Print" value="Imprimir Relat�rio">
	</td>
  </tr>
	</form>
  <?php } 
  }?>
	<tr>
		<td>
</td>
  </tr>
</table>
<?php print footer(); ?>